﻿using System;
using System.Reflection;

namespace ExpressesClass.Method
{
    public class TypeControl
    {
        /// <summary>
        /// 泛型中字符串格式整理
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static T Format<T>(T obj)
        {
            Type type = obj.GetType();

            foreach (PropertyInfo info in type.GetProperties())
            {
                object propertyValue = obj == null ? null : info.GetValue(obj);
                Type propType = info.PropertyType;

                if (propType == typeof(string) && propertyValue != null)
                {
                    info.SetValue(obj, propertyValue.ToString().Replace(Convert.ToChar(10).ToString(), ""));
                }
            }
            return obj;
        }
    }
}
